#include <iostream>
using namespace std;

// explicit 适用于单参数的构造函数，主要是避免隐式类型转换
class HaveExplicit
{
public:
    int m_i;
    explicit HaveExplicit(int i) : m_i(i) {}
};

class NoExplicit
{
public:
    int m_i;
    NoExplicit(int i) : m_i(i) {}
};

void test_explicit(HaveExplicit he)
{
    std::cout << he.m_i << std::endl;
}

void test_implicit(NoExplicit ne)
{
    std::cout << ne.m_i << std::endl;
}

int main()
{
    // test_explicit(1); // wrong: 1 must be HaveExplicit(1)
    test_implicit(1); // right: 1 transform to NoExplicit(1) implicitly

    // sometimes we don't like 1 transform to NoExplicit(1) implicitly because it may cause some unexpected errors.
}
